<template>
  <div>
    <!-- 业务自评 -->
    <template>
      <div class="btn-line">
        <a-select
          @change="handleSearch"
          style="width:200px"
          placeholder="请选择"
          v-model="dictId"
          @select="handleAction"
        >
          <a-select-option v-for="item in dict" :key="item.key" :value="item.key" >
            {{ item.name }}
          </a-select-option>
        </a-select>
      </div>
      <div class="mt20">
        <a-table
          v-if="dictId == 1"
          class="risk-mini-size-table "
          :loading="pagination.loading"
          :columns="dataColumns"
          :data-source="dataList"
          :pagination="pagination"
          bordered
          @change="pageChange"
          rowKey="id"
          :scroll="{ x: true }"
        >
          <template slot="textOver" slot-scope="text">
            <span class="text-over" :title="text">{{ text }}</span>
          </template>
          <template slot="serialNumber" slot-scope="text, record">
            <a type="link" @click="handleDetail(record)">{{ text }}</a>
          </template>
          <template slot="switch" slot-scope="text, record">
            <a-switch   v-if="record.questionNo" checked-children="是" un-checked-children="否"   v-model="record.currentYearRisk" :disabled="true"/>
            <a-switch  v-else  checked-children="是" un-checked-children="否"   v-model="record.currentYearRisk" :disabled="true"/>
          </template>
<!--          <template slot="relatePunish" slot-scope="text, record">-->
<!--            <a-textarea v-model="record.relatePunish" :auto-size="{ minRows: 3}"></a-textarea>-->
<!--          </template>-->
          <template slot="questionNo" slot-scope="text, record">
            <a-button v-if="record.currentYearRisk && !record.questionNo"  @click="handAddQuestion(record)">创建问题单</a-button>
            <template v-else-if="record.questionNo != undefined  && record.questionNo != ''" v-for="question in record.questionNo.split(',')">
              <a-tag
                      :key="record.id + question"
                      @click="routerToQuestion(question)"
                      style="cursor:pointer;margin-bottom:5px;"
                      color="purple"
              >
                {{ question }}
              </a-tag>
            </template>
          </template>

          <template slot="file" slot-scope="text, record" v-if="record">

          </template>
        </a-table>
        <a-table
                v-if="dictId == 2"
                class="risk-mini-size-table "
                :loading="pagination.loading"
                :columns="dataColumns2"
                :data-source="dataListAct"
                :pagination="pagination"
                bordered
                @change="pageChange"
                rowKey="id"
                :scroll="{ x: true }"
        >
          <template slot="textOver" slot-scope="text">
            <span class="text-over" :title="text">{{ text }}</span>
          </template>
          <template slot="serialNumber" slot-scope="text, record">
            <a type="link" @click="handleDetail(record)">{{ text }}</a>
          </template>
          <template  slot="fitActual" slot-scope="text">
            <span :title="text">{{ text?'是':'否' }}</span>
          </template>
          <template slot="needOpt" slot-scope="text">
            <span :title="text">{{ text?'是':'否' }}</span>
          </template>
          <template slot="executeDegree" slot-scope="text ,record">
            <span :title="text" v-if="record.executeDegree ==1 ">100%执行</span>
            <span :title="text" v-if="record.executeDegree ==2 ">部分执行</span>
            <span :title="text" v-if="record.executeDegree ==3 ">没有执行</span>
          </template>

          <template slot="needOpt" slot-scope="text, record" >
            <a-switch  checked-children="是" un-checked-children="否" v-model="record.needOpt"   disabled="true"/>
          </template>
          <template slot="associated" slot-scope="text, record, index">
            <template v-if="record.needOpt">
              <span>{{text}}</span>
              <a-button  type="primary" size="small" @click="handleAsso( record, index)" shape="circle" icon="search" />
            </template>
          </template>

        </a-table>
      </div>
    </template>
    <ChooseModal ref="choosepro" @ok="choosePro"></ChooseModal>
  </div>
</template>
<script>
import { getRiskAction, postRiskAction } from '@/api/manage';
import LuckSheetPaste from '@/components/tools/LuckSheetPaste';
import * as api from '@/api/api';
import { CommonMixis } from '@/mixins/CommonMixis';
import ChooseModal from "../../evaluation/assessPro/chooseModal";
export default {
  name: 'DataColBy1',
  mixins: [CommonMixis],
  components: {
    ChooseModal
  },
  data() {
    return {
      dict: [
        { name: '风险点评价', key: 1 },
        { name: '控制活动评价', key: 2 },
      ],
      dictId: 1,
      pagination: {
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '30', '50'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条';
        },
        total: 0,
        loading: false,
      },
      dataColumns: [
        {
          title: '评价单号',
          dataIndex: 'serialNumber',
          align: 'center',
          width: 130 ,
          align: 'center' ,
          scopedSlots: { customRender: 'serialNumber' }
        },
        {
          title: '评价人',
          dataIndex: 'receiveUser',
          align: 'center',
          width: 120
        },
        {
          title: '评价年度',
          width: 120,
          dataIndex: 'evaluateYear',
          align: 'center',
        },
        {
          title: '本年度是否发生相关风险',
          width: 100,dataIndex: 'currentYearRisk',
          align: 'center',
          scopedSlots: { customRender: 'switch' }
          },
        {
          title: '相关扣罚（月薪评议等级）',
          width: 150,
          dataIndex: 'relatePunish',
          align: 'center',
          scopedSlots: { customRender: 'relatePunish' }},
        {
          title: '关联问题单号',
          width: 100,
          dataIndex: 'questionNo',
          align: 'center',
          scopedSlots:{customRender:'questionNo'}
        },
        {
          title: '风险点风控等级',
          width: 100,
          dataIndex: 'riskLevel',
          align: 'center',
        },
      ],
      dataColumns2: [
        {
          title: '评价单号',
          dataIndex: 'serialNumber',
          align: 'center',
          width: 130 ,
          scopedSlots: { customRender: 'serialNumber' }
        },
        {
          title: '评价人',
          dataIndex: 'receiveUser',
          align: 'center',
          width: 80
        },
        {
          title: '评价年度',width: 80,
          dataIndex: 'evaluateYear',
          align:'center' ,
        },
        {
          title: '控制活动编号',
          width: 100,
          align:'center' ,
          dataIndex: 'riskActivityNo',},
        {
          title: '控制活动',
          width: 120,
          align:'center' ,
          dataIndex: 'riskActivity'
        },
        {
          title: '业务流程细项是否与实际一致',
          width: 120,
          align:'center' ,
          dataIndex: 'fitActual' ,
          scopedSlots: { customRender: 'fitActual' }
        },
        {
          title: '控制活动执行程度',
          width: 110,
          dataIndex: 'executeDegree',
          scopedSlots: { customRender: 'executeDegree' }
        },
        {
          title: '控制活动相关附件',
          width: 120,
          dataIndex: 'attachName',
          align:'center' ,
          scopedSlots: { customRender: 'attach' }
        },
        {
          title: '现阶段实际执行的控制活动',
          width: 120,
          align:'center' ,
          dataIndex: 'currentActivity',
        },
        {
          title: '控制活动是否需优化',
          width: 100,
          dataIndex: 'needOpt',
          align: 'center',
          scopedSlots: { customRender: 'needOpt' }
        },
        {
          title: '关联优化单号',
          width: 150,
          dataIndex: 'optNo',
          align: 'center',
          scopedSlots: { customRender: 'associated' }}
        ,
      ],
      dataList: [],
      dataListAct: [],
      url: {
        list: '/incEvaluateActivity/optPage',
        getList:'/incEvaluateRisk/getMatrixRiskList', //风险
        activityList:'/incEvaluateActivity/getEvaluateActPage', //活动
        questionByNo:'/incEvaluateRisk/questionByNo',
      },
    };
  },
  mounted() {
    let riskId  = this.$route.query.id
    let companyCode = this.$route.query.companyCode;
    let manageCode = this.$route.query.manageCode;
    let businessModelId = this.$route.query.businessModelId;
    this.$set(this.pagination , 'riskId' , riskId)
    this.$set(this.pagination , 'companyCode' ,companyCode)
    this.$set(this.pagination , 'manageCode' ,manageCode)
    this.$set(this.pagination , 'businessModelId' ,businessModelId)
    this.getInitData();
  },
  methods: {
    handleSearch(){
      this.pagination.current = 1;
      this.getInitData();
    },
    /**
     * 查询列表
     */
    pageChange(page) {
      this.pagination.current = page.current;
      this.pagination.pageSize = page.pageSize;
      if (this.dictId == 1){
        this.getInitData();
      }

      if (this.dictId == 2){
        this.initData();
      }
    },

    handleDetail(item){
      var routeUrl = this.$router.resolve({
        path: `/internal/eva/deteva/2/` + item.orderId ,
        query:{fromMartrix:true}
      });
      window.open(routeUrl.href, '_blank');
    },
    handleAsso(item , index){
      this.$refs.choosepro.handleAddOpen(item.id,item.riskNo,item.riskId)
    },
    handleAction(value){
      if (value == 1){
        this.$set(this.pagination , 'current' , 1)
        this.getInitData()
      }
      if (value == 2){
        this.$set(this.pagination , 'current' , 1)
        this.initData();
      }
    },
    handAddQuestion(record){
      // this.rowId = record.id;
      // this.$refs.createQuestion.handleEdit();
      var routeUrl = this.$router.resolve({
        path: '/internal/pro/addlssue?createType=1&evaluateRiskId=' + record.id
      });
      window.open(routeUrl.href, '_blank');
    } ,
    routerToQuestion(no) {

      getRiskAction(this.url.questionByNo,{questionNo:no}).then(res => {
        if (res.code == 0 && res.data) {
          let routeUrl = this.$router.resolve({path: '/internal/pro/addlssue?id=' + res.data.id});
          window.open(routeUrl.href, '_blank');
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    initData() {
      if(!this.refreshLoading){
        this.refreshLoading = true;
        getRiskAction(this.url.activityList ,{
          pageNo: this.pagination.current,
          pageSize: this.pagination.pageSize,
          companyCode: this.pagination.companyCode,
          businessModelId: this.pagination.businessModelId,
          type:4 ,
          riskId:this.pagination.riskId ,
          manageCode: this.pagination.manageCode,
        }).then(res => {
          const result = res.data;
          if (res.code == 0) {
            this.dataListAct = result.records;
            this.pagination.total = result.total
          } else {
            this.$message.error(res.msg);
          }
          this.refreshLoading = false;
        });
      }
    },
    getInitData() {
      this.pagination.loading = true;
      getRiskAction(this.url.getList, {
        pageNo: this.pagination.current,
        pageSize: this.pagination.pageSize,
        type:4 ,
        companyCode: this.pagination.companyCode,
        businessModelId: this.pagination.businessModelId,
        manageCode: this.pagination.manageCode,
        riskId:this.pagination.riskId ,
        deptId:this.pagination.deptId,
      }).then(res => {
        const result = res.data;
        if (res.code === 0) {
          this.dataList = result.records;
          this.pagination.total = result.total;
        } else {
          this.$message.error('查询列表失败');
        }
      });
      this.pagination.loading = false;
    },
  }
};
</script>
<style lang="scss" scoped>
@import '../../main.scss';
.mt20{
  margin-top: 20px;
}
</style>
